package com.ruoyi.project.monitor.warnmessage.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.monitor.warnmessage.domain.WarnMessage;
import com.ruoyi.project.monitor.warnmessage.service.IWarnMessageService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 告警消息Controller
 * 
 * @author shixiangwen
 * @date 2020-04-09
 */
@Controller
@RequestMapping("/monitor/warnmessage")
public class WarnMessageController extends BaseController
{
    private String prefix = "monitor/warnmessage";

    @Autowired
    private IWarnMessageService warnMessageService;

    @RequiresPermissions("monitor:warnmessage:view")
    @GetMapping()
    public String warnmessage()
    {
        return prefix + "/warnmessage";
    }

    /**
     * 查询告警消息列表
     */
    @RequiresPermissions("monitor:warnmessage:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(WarnMessage warnMessage)
    {
        startPage();
        List<WarnMessage> list = warnMessageService.selectWarnMessageList(warnMessage);
        return getDataTable(list);
    }

    /**
     * 导出告警消息列表
     */
    @RequiresPermissions("monitor:warnmessage:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WarnMessage warnMessage)
    {
        List<WarnMessage> list = warnMessageService.selectWarnMessageList(warnMessage);
        ExcelUtil<WarnMessage> util = new ExcelUtil<WarnMessage>(WarnMessage.class);
        return util.exportExcel(list, "warnmessage");
    }

    /**
     * 新增告警消息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存告警消息
     */
    @RequiresPermissions("monitor:warnmessage:add")
    @Log(title = "告警消息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(WarnMessage warnMessage)
    {
        return toAjax(warnMessageService.insertWarnMessage(warnMessage));
    }

    /**
     * 修改告警消息
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        WarnMessage warnMessage = warnMessageService.selectWarnMessageById(id);
        mmap.put("warnMessage", warnMessage);
        return prefix + "/edit";
    }

    /**
     * 修改保存告警消息
     */
    @RequiresPermissions("monitor:warnmessage:edit")
    @Log(title = "告警消息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(WarnMessage warnMessage)
    {
        return toAjax(warnMessageService.updateWarnMessage(warnMessage));
    }

    /**
     * 删除告警消息
     */
    @RequiresPermissions("monitor:warnmessage:remove")
    @Log(title = "告警消息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(warnMessageService.deleteWarnMessageByIds(ids));
    }
}
